package com.esreport.logstash.tracker;

/**
 * @author xuweiwei
 * @date 2018/12/25
 */
public class LogDescribe {
    private String dir;
    private String name;
    private String regexDesc;



    public String getDir() {
        return dir;
    }

    public void setDir(String dir) {
        this.dir = dir;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public String getRegexDesc() {
        return regexDesc;
    }

    public void analyzer() {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < name.length(); i++) {
            char c = name.charAt(i);
            if (c == '*') {
                result.append("[^/\\\\]*");
            } else if (c == '?') {
                result.append("[^/\\\\]?");
            } else if (c == '[') {
                result.append("\\[");
            } else if (c == ']') {
                result.append("\\]");
            } else if (c == '\\') {
                result.append("\\\\");
            } else {
                result.append("[").append(c).append(']');
            }
        }
        regexDesc = result.toString();
    }

    public static void main(String[] args) {
        LogDescribe logDescribe = new LogDescribe();
        logDescribe.setDir("D:/test1");
        logDescribe.setName("*.log");
        logDescribe.analyzer();
        System.out.println(logDescribe.getRegexDesc());
    }
}
